import { defineStore } from 'pinia';
import carApi from '@/sheep/api/car';

const pkCar = defineStore({
	id: 'pkCar',
	state: () => ({
		list: [], // pk列表
		listIds: [], // pk列表id
		selectedList: [], // 已选列表
		selectedIds: [], // 已选列表id
	}),
	actions: {
		getList() {
			
		},
		// 添加对比
		add(carInfo) {
			if( !this.listIds.includes(carInfo.car_id) ) {
				this.listIds.push(carInfo.car_id)
				this.list.push(carInfo)
			}
		},
		delete(carInfo) {
			this.listIds = this.listIds.filter(id => id != carInfo.car_id)
			this.list = this.list.filter(item => item.car_id != carInfo.car_id)
		},
		// 选择
		selectSingle(carId) {
			if (!this.selectedIds.includes(carId)) {
				this.selectedIds.push(carId);
			} else {
				this.selectedIds.splice(this.selectedIds.indexOf(carId), 1);
			}
			console.log(this.selectedIds)
		},
		
	}
})

export default pkCar;